<?php

class Add implements Action {

<#list clients.displayColumns as column>
  private ${column.name};
</#list>

  public function setParams($param = null) {
  <#list clients.displayColumns as column>
    $this->${column.name} = $_POST['${column.name}'];
  </#list>
  }

  public function validate($response) {
  <#list clients.displayColumns as column>
    <#if column.is("NOT_NULL") == true>
    if ($this->${column.name} == "") {
      $response->addError("${column.name} missing");
    }
    </#if >
  </#list>
  }

  public function execute($response) {
    $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
    mysql_select_db(DB_NAME, $con) or die(mysql_error());
    $sql = "INSERT INTO clients (<#list clients.displayColumns as column>${column.name}<#if column_has_next>,</#if></#list>) 
            VALUES ('$this->name','$this->bday','$this->address','$this->cellPhone','$this->eMail', NOW())";
    mysql_query($sql, $con) or die(mysql_error());
  }

  public function getContentType() {
    return JSON;
  }

  public function getHTTPMethod() {
    return POST;
  }

}

?>
